import { computed } from 'vue'

export function usePerm() {
  const permSet = computed<Set<string>>(() => {
    try {
      const p = localStorage.getItem('profile')
      if (!p) return new Set()
      const perms = (JSON.parse(p).perms as string) || ''
      return new Set(perms.split(',').map(s => s.trim()).filter(Boolean))
    } catch {
      return new Set()
    }
  })

  function hasPerm(code: string): boolean { return permSet.value.has(code) }
  function hasAny(codes: string[]): boolean { return codes.some(c => hasPerm(c)) }

  return { hasPerm, hasAny, permSet }
}





